home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / TimeSchedulerdefs.h < prev    next >
C/C++ Source or Header  |  1989-10-19  |  3KB  |  119 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23.  
  24.  
  25. #ifndef _TimeSchedulerdefs_h
  26. #define _TimeSchedulerdefs_h 1
  27. #pragma once
  28.  
  29. #include <Thread.h>
  30.  
  31. class TimeScheduler {
  32.     Thread *pThread;
  33.     double pTime;
  34. public:
  35.     TimeScheduler();
  36.     TimeScheduler(Thread *p);
  37.     TimeScheduler(Thread *p, double when);
  38.  
  39.     operator==(TimeScheduler &p);
  40.     operator<=(TimeScheduler &p);
  41.  
  42.     Thread *thread();
  43.     double time();
  44. };
  45.  
  46. inline Thread*
  47. TimeScheduler::thread()
  48. {
  49.     return(pThread);
  50. }
  51.  
  52. inline double
  53. TimeScheduler::time()
  54. {
  55.     return(pTime);
  56. }
  57.  
  58. inline TimeScheduler::TimeScheduler()
  59. {
  60.     pThread = 0;
  61.     pTime = 0;
  62. }
  63.  
  64. inline TimeScheduler::TimeScheduler(Thread *p)
  65. {
  66.     pThread = p;
  67.     pTime = 0;
  68. }
  69.  
  70. inline TimeScheduler::TimeScheduler(Thread *p, double w)
  71. {
  72.     pThread = p;
  73.     pTime = w;
  74. }
  75.  
  76. inline int TimeScheduler::operator==(TimeScheduler &p)
  77. {
  78.     return( (pTime == p.pTime)
  79.        && (pThread -> priority() == (p.thread() -> priority())));
  80. }
  81.  
  82. inline int TimeScheduler::operator<=(TimeScheduler &p)
  83. {
  84.     return(
  85.        (pTime <  p.pTime)
  86.        || ( (pTime == p.pTime)
  87.            && (pThread -> priority() <= (p.thread() -> priority()))) );
  88. }
  89.  
  90. // equality operator
  91. #ifndef TimeSchedulerEQ
  92. #define TimeSchedulerEQ(a, b)  ((a) == (b))
  93. #endif
  94.  
  95. // less-than-or-equal
  96. #ifndef TimeSchedulerLE
  97. #define TimeSchedulerLE(a, b)  ((a) <= (b))
  98. #endif
  99.  
  100. // comparison : less-than -> < 0; equal -> 0; greater-than -> > 0
  101. #ifndef TimeSchedulerCMP
  102. #define TimeSchedulerCMP(a, b) ( ((a) <= (b))? (((a) == (b))? 0 : -1) : 1 )
  103. #endif
  104.  
  105. // hash function
  106. #ifndef TimeSchedulerHASH
  107. extern unsigned int hash(TimeScheduler&);
  108. #define TimeSchedulerHASH(x)  hash(x)
  109. #endif
  110.  
  111. // initial capacity for structures requiring one
  112.  
  113. #ifndef DEFAULT_INITIAL_CAPACITY
  114. #define DEFAULT_INITIAL_CAPACITY 100
  115. #endif
  116.  
  117.  
  118. #endif
  119.